import functools
class Solution:
    def count(self, num1: str, num2: str, min_sum: int, max_sum: int) -> int:
        base = 10 ** 9 + 7
        self.ans = 0
        if len(num1) == len(num2):
            n = len(num1)
            @functools.cache
            def dfs3(j, total):
                if j == n:
                    if total == 0:
                        return 1
                    else:
                        return 0
                else:
                    left_bit = n - j
                    if left_bit * 9 < total:
                        return 0
                    else:
                        ans = 0
                        for k in range(min(10, total + 1)):
                            ans += dfs3(j + 1, total - k)
                        return ans % base


            @functools.cache
            def dfs_range(j, total_val):
                if j == n:
                    if min_sum <= total_val <= max_sum:
                        return 1
                    else:
                        return 0
                else:
                    if total_val <= max_sum:
                        need_min = min_sum - total_val
                        need_max = max_sum - total_val
                        ans = 0
                        for k in range(max(need_min, 0), need_max + 1):
                            ans += dfs3(j, k)
                        return ans % base
                    else:
                        return 0
            
            @functools.cache
            def dfs_find_max(j, total):
                if total < 0:
                    return 0
                if j == n:
                    if min_sum <= total <= max_sum:
                        return 1
                    else:
                        return 0
                else:
                    ans = 0
                    ans += dfs_find_max(j + 1, total - int(num1[j]))
                    for k in range(int(num1[j]) + 1, min(total + 1, 10)):
                        ans += dfs3(j + 1, total - k)
                    return ans % base


            @functools.cache
            def dfs_find_min(j, total):
                if total < 0:
                    return 0
                if j == n:
                    if min_sum <= total <= max_sum:
                        return 1
                    else:
                        return 0
                else:
                    ans = 0
                    ans += dfs_find_min(j + 1, total - int(num2[j]))
                    for k in range(int(num2[j])):
                        ans += dfs3(j + 1, total - k)
                    return ans % base                

            def dfs(i, total_val):
                if i < n:
                    ans = 0
                    if num1[i] == num2[i]:
                        total_val += int(num1[i])
                        if total_val <= max_sum:
                            ans = dfs(i + 1, total_val)
                    if num1[i] < num2[i]:
                        next_val = total_val +  int(num2[i])
                        if next_val <= max_sum:
                            ans += dfs_find_min(i + 1, next_val)
                        next_val = total_val +  int(num1[i])
                        if next_val <= max_sum:
                            ans += dfs_find_max(i + 1, next_val)
                        for k in range(int(num1[i]) + 1, int(num2[i])):
                            ans += dfs_range(i + 1, total_val + k)
                    return ans % base
                else:
                    if total_val >= min_sum:
                        return 1
                    else:
                        return 0
            return dfs(0, 0)
        else:
            @functools.cache
            def dfs3(left_bit, total):
                if left_bit == 0:
                    if total == 0:
                        return 1
                    else:
                        return 0
                else:
                    if left_bit * 9 < total:
                        return 0
                    else:
                        ans = 0
                        for k in range(min(10, total + 1)):
                            ans += dfs3(left_bit - 1, total - k)
                        return ans % base
            
            @functools.cache
            def dfs_range(left_bit, total_val):
                if left_bit == 0:
                    if min_sum <= total_val <= max_sum:
                        return 1
                    else:
                        return 0
                else:
                    if total_val <= max_sum:
                        need_min = min_sum - total_val
                        need_max = max_sum - total_val
                        ans = 0
                        for k in range(max(need_min, 0), need_max + 1):
                            ans += dfs3(left_bit, k)
                        return ans % base
                    else:
                        return 0
            
            @functools.cache
            def dfs_find_max(j, total, n):
                if total < 0:
                    return 0
                if j == n:
                    if min_sum <= total <= max_sum:
                        return 1
                    else:
                        return 0
                else:
                    ans = 0
                    ans += dfs_find_max(j + 1, total - int(num1[j]))
                    for k in range(int(num1[j]) + 1, min(total + 1, 10)):
                        ans += dfs3(j + 1, total - k)
                    return ans % base


            @functools.cache
            def dfs_find_min(j, total, n):
                if total < 0:
                    return 0
                if j == n:
                    if min_sum <= total <= max_sum:
                        return 1
                    else:
                        return 0
                else:
                    ans = 0
                    ans += dfs_find_min(j + 1, total - int(num2[j]))
                    for k in range(int(num2[j])):
                        ans += dfs3(j + 1, total - k)
                    return ans % base
                
            def dfs1(i, total_val, n):
                if i < n:
                    ans = 0
                    next_val = total_val +  int(num1[i])
                    if next_val <= max_sum:
                        ans += dfs1(i + 1, next_val, n)
                    for k in range(int(num1[i]) + 1, 10):
                        ans += dfs_range(n - i - 1, total_val + k)
                    return ans % base
                else:
                    if total_val >= min_sum:
                        return 1
                    else:
                        return 0
            
            def dfs2(i, total_val, n):
                if i < n:
                    ans = 0
                    next_val = total_val + int(num2[i])
                    if next_val <= max_sum:
                        ans += dfs2(i + 1, next_val, n)
                    if i == 0:
                        for k in range(1, int(num2[i])):
                            ans += dfs_range(n - i - 1, total_val + k)
                    else:
                        for k in range(int(num2[i])):
                            ans += dfs_range(n - i - 1, total_val + k)                        
                    return ans % base
                else:
                    if total_val >= min_sum:
                        return 1
                    else:
                        return 0
                    
            n1 = len(num1)
            n2 = len(num2)
            ans = 0

            for k in range(n1 + 1, n2):
                for i in range(1, 10):
                    ans = (ans + dfs_range(k - 1, i)) % base
            ans = (ans + dfs1(0, 0, n1)) % base
            ans = (ans + dfs2(0, 0, n2)) % base
            return ans


data = Solution()
num1 = '6312'
num2 = '9416'
min_sum = 29
max_sum = 30
print(data.count(num1, num2, min_sum, max_sum))